package easy

func NumRookCaptures(board [][]byte) int {
	cnt, st, ed := 0, 0, 0
	dx := []int{0, 1, 0, -1}
	dy := []int{1, 0, -1, 0}
	for i := 0; i < 8; i++ {
		for j := 0; j < 8; j++ {
			if board[i][j] == 'R' {
				st = i
				ed = j
				break
			}
		}
	}
	for i := 0; i < 4; i++ {
		for step := 0; ; step++ {
			tx := st + dx[i]*step
			ty := ed + dy[i]*step
			if tx < 0 || tx >= 8 || ty < 0 || ty >= 8 || board[tx][ty] == 'B' {
				break
			}
			if board[tx][ty] == 'p' {
				cnt++
				break
			}
		}
	}
	return cnt
}
